home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / gms_dev.lha / GMSDev / Source / C / Blitter / PenBounce.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-01  |  2.2 KB  |  88 lines

  1. /* Dice: 1> dcc -l0 -mD dpk.o tags.o BounceLine.c -o BounceLine
  2. **
  3. ** Line bouncing demo that works on a screen of any type of dimensions as
  4. ** specified by the user in GMSPrefs.
  5. */
  6.  
  7. #include <proto/dpkernel.h>
  8.  
  9. BYTE *ProgName      = "Bounce Line (Pens based)";
  10. BYTE *ProgAuthor    = "Paul Manias";
  11. BYTE *ProgDate      = "August 1998";
  12. BYTE *ProgCopyright = "DreamWorld Productions (c) 1996-1998.  Freely distributable.";
  13. BYTE *ProgShort     = "Line bouncing demo (Pens based).";
  14.  
  15. void main(void)
  16. {
  17.   struct GScreen *Screen;
  18.   struct JoyData *JoyData;
  19.   LONG palette[] = { PALETTE_ARRAY, 2, 0x000000L, 0x80f0f0L };
  20.   int  sx,sy,ex,ey;
  21.   int  dsx,dsy,dex,dey;
  22.  
  23.   if (Screen = InitTags(NULL,
  24.       TAGS_SCREEN,    NULL,
  25.         GSA_BitmapTags, NULL,
  26.         BMA_Palette,    palette,
  27.         TAGEND,         NULL,
  28.       GSA_Attrib,     SCR_DBLBUFFER,
  29.       TAGEND)) {
  30.  
  31.      sx = SlowRandom(Screen->Width);  dsx = -1;
  32.      sy = SlowRandom(Screen->Height); dsy = 2;
  33.      ex = SlowRandom(Screen->Width);  dex = 3;
  34.      ey = SlowRandom(Screen->Height); dey = 1;
  35.  
  36.      if (JoyData = Init(Get(ID_JOYDATA),NULL)) {
  37.  
  38.         Display(Screen);
  39.  
  40.         SetPenShape(Screen->Bitmap,PSP_CIRCLE,2);
  41.         SetRGBPen(Screen->Bitmap,0xffffffL);
  42.  
  43.         do
  44.         {
  45.           Clear(Screen->Bitmap);
  46.           Query(JoyData);
  47.           sx += dsx;
  48.           sy += dsy;
  49.           ex += dex;
  50.           ey += dey;
  51.  
  52.           if(sx<0) { sx = 0; dsx = -(dsx); }
  53.           if(sy<0) { sy = 0; dsy = -(dsy); }
  54.           if(ex<0) { ex = 0; dex = -(dex); }
  55.           if(ey<0) { ey = 0; dey = -(dey); }
  56.  
  57.           if(sx>Screen->Width-1) {
  58.             sx  = Screen->Width-1;
  59.             dsx = -(dsx);
  60.           }
  61.  
  62.           if(sy>Screen->Height-1) {
  63.             sy  = Screen->Height-1;
  64.             dsy = -(dsy);
  65.           }
  66.  
  67.           if(ex>Screen->Width-1) {
  68.             ex  = Screen->Width-1;
  69.             dex = -(dex);
  70.           }
  71.  
  72.           if(ey>Screen->Height-1) {
  73.             ey  = Screen->Height-1;
  74.             dey = -(dey);
  75.           }
  76.  
  77.           PenLine(Screen->Bitmap,sx,sy,ex,ey,0x01010101);
  78.           WaitAVBL();
  79.           SwapBuffers(Screen);
  80.         } while (!(JoyData->Buttons & JD_LMB));
  81.  
  82.      Free(JoyData);
  83.      }
  84.   Free(Screen);
  85.   }
  86. }
  87.  
  88.